/*
 * Copyright (c) 2025 UCT Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
  * _TableName_ViewModel 类用于表示实体数据的视图模型。可以添加无需持久化仅用于界面显示的状态
  * 包含了实体的各种属性，并提供了从 ORM 实体对象转换为视图模型对象的方法。
  * 同时也提供了将视图模型对象转换为 ORM 实体对象的方法。
  * 使用示例：创建实例 const _table_name_Data = new _TableName_ViewModel({ id: '1', link: 'test' });
  * 从 ORM 实体转换 const _table_name_Obj = new _table_name_(); _table_name_Obj.id = '1'; const viewModel = _TableName_ViewModel.fromEntity(_table_name_Obj);
  * 转换回 ORM 实体 const new_TableName_Obj = viewModel.toEntity();
  *
  */
import { _table_name_, edit_TableName_Params } from 'commondb';
//#region Human-Code Preservation

//#endregion Human-Code Preservation
@ObservedV2
export class _TableName_ViewModel {
REPLACE_VIEWMODEL

  constructor(data?: edit_TableName_Params) {
    if (data) {
REPLACE_VIEWMODELCONSTRUCTOR
    }
  }

/**
   * 获取所有成员变量的key
   * @param instance 实体视图模型实例
   * @returns string[] 成员变量名称数组
   */
  static getKeys(): string[] {
    return [
REPLACE_VIEWMODELKEYS
    ];
  }

  /**
   * 获取指定的成员变量key和对应的值
   * @param instance 实体视图模型实例
   * @param keys 要获取的key名称数组
   * @returns string 筛选后的成员变量名称和值
   */
  static getSpecificKeys(instance: _TableName_ViewModel, keys: string[]): string {
    return keys.map(key => {
      return `${key}`;
    }).join(', ');
  }

  /**
   * 获取指定key的值
   * @param instance 实体视图模型实例
   * @param key 属性名
   * @returns string 属性值的字符串表示
   */
  static getValue(instance: _table_name_ | _TableName_ViewModel, key: string): string {
    switch (key) {
REPLACE_VIEWMODELGETVALUE
      default: return '';
    }
  }

  /**
   * 将 ORM 实体对象转换为视图模型对象
   * @param _table_name_ ORM实体对象
   */
  static fromEntity(_table_name_Obj: _table_name_): _TableName_ViewModel {
    const params: edit_TableName_Params = {
REPLACE_VIEWMODELFROMENTITY
    };
    return new _TableName_ViewModel(params);
  }

  /**
   * 将视图模型对象转换为 ORM 实体对象
   */
  toEntity(): _table_name_ {
    const _table_name_Obj = new _table_name_();
REPLACE_VIEWMODELTOENTITY
    return _table_name_Obj;
  }

  updateDeletedAt(deleted_at : string | null): void {
    this.deleted_at = deleted_at;
  }
//#region Human-Code Preservation

//#endregion Human-Code Preservation
}
//#region Human-Code Preservation

//#endregion Human-Code Preservation